using System.Net;

namespace TechHeadBrothers.Portal.Web.SilverlightStreaming.Commands
{
    public abstract class FilesetCommand
    {
        protected SilverlightStreamingManager _manager;
        private readonly string _requestAccountUriString;

        /// <summary>
        /// Initializes a new instance of the <see cref="FilesetCommand"/> class.
        /// </summary>
        /// <param name="manager">The manager.</param>
        public FilesetCommand(SilverlightStreamingManager manager)
        {
            _manager = manager;
            _requestAccountUriString = string.Format("{0}/{1}", _manager.ServiceRoot, _manager.AccountID);
        }

        /// <summary>
        /// Gets the REST http web request.
        /// </summary>
        /// <param name="fileSetName">Name of the file set.</param>
        /// <returns></returns>
        public HttpWebRequest GetRESTHttpWebRequest(string fileSetName)
        {
            HttpWebRequest request =
                (HttpWebRequest)HttpWebRequest.Create(string.Format("{0}/{1}", _requestAccountUriString, fileSetName));

            request.Credentials = new NetworkCredential(_manager.AccountID, _manager.AccountKey);

            ConfigureHttpWebRequest(request);

            return request;
        }

        /// <summary>
        /// Configures the HTTP web request.
        /// </summary>
        /// <param name="request">The request.</param>
        protected abstract void ConfigureHttpWebRequest(HttpWebRequest request);
    }
}